<template>
  <div class="section_common">
    <div class="main">
      <el-form ref="form" label-width="100px">
        <!--<el-form-item label="所属仓库" required>
          <el-select
            v-model="form.region"
            size="mini"
            placeholder="请选择所属仓库"
          >
            <el-option label="上雪仓" value="shenzhen"></el-option>
            <el-option label="东莞仓" value="hefei"></el-option>
          </el-select>
        </el-form-item>-->

        <el-form-item label="所属仓库" required>
          <el-radio v-model="area" label="1">东莞仓</el-radio>
          <el-radio v-model="area" label="2">上雪仓</el-radio>
        </el-form-item>

        <el-form-item label="费用名称" required>
          <el-input v-model="costname" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="实际用途" required>
          <el-input v-model="tuse" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="金额(元)" required>
          <el-input v-model="money" size="mini" @keyup.enter="comdify"  @input="comdify"></el-input><!--v-on:keyup="comdify"-->
        </el-form-item>
        <el-form-item label="特殊备注">
          <el-input v-model="other" size="mini"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" size="mini" @click="submitPost"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import { Toast} from "vant";
export default {
  data() {
    return {
      area:"1",
      costname:"",
      tuse:"",
      money:"",
      other:"",

      nowUser:"",
      title: "费用登记",

      addExpenseApply: '/mobiles/addExpenseApply',

    };
  },
  created() {
    this.nowUser=JSON.parse(localStorage.getItem('userInfo')).userId;
  },
  methods: {

    comdify() {
      this.money = this.money.replace(/[^\d.]/g, "");
      let re = /\d{1,3}(?=(\d{3})+$)/g;
      let n1 = this.money.replace(/^(\d+)((\.\d+)?)$/, function (s, s1, s2) {
        return s1.replace(re, "$&,") + s2;
      });
      //return n1;
      this.money=n1;
    },


    // 返回
    goBack() {
      this.$router.go(-1);
    },
    // 提交
    submitPost() {
      if (!this.isNull()) return false;

      this.$https.post(this.addExpenseApply, {
        nowUser:this.nowUser,
        area: this.area,
        costname:this.costname,
        tuse:this.tuse,
        money:this.money,
        other:this.other,

      }).then(res => {
        res;
        Toast("费用登记成功");
        this.$router.go(-1);
      }).catch(err => {
        console.log(err)
      });
    },
    //判断相关数据是否为空
    isNull() {
      if (this.checked1 == '') {
        this.$toast("请选择所属仓库");
        return false;
      }
      if (this.costname=='') {
        this.$toast("费用名称不能为空");
        return false;
      }
      if (this.tuse=='') {
        this.$toast("实际用途不能为空");
        return false;
      }
      if (this.money=='') {
        this.$toast("金额不能为空");
        return false;
      }

      return true;
    },
  },
};
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-items: center;
  margin: 0 auto;
  .el-form {
    padding-right: 10px;
    .el-form-item {
      .el-form-item__label {
        line-height: 16px;
      }
      margin-bottom: 5px;
    }
  }
}
</style>